package com.define.ssh.action.log;

import java.util.HashMap;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.ParentPackage;

import com.define.ssh.action.admin.BaseAdminAction;
import com.define.ssh.model.TbLog;
import com.define.ssh.service.TbLogService;

/**
 * 系统日志
 * 
 */
@ParentPackage("admin")
public class SystemLogAction extends BaseAdminAction {

	/** 页面传递参数过来 */
	protected int pageSize;
	protected int pageNum;

	@Resource(name = "tbLogServiceImpl")
	private TbLogService tbLogService;

	private TbLog tbLog;

	/**
	 * 列表页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() {
		final HashMap<String, Object> searchMap = new HashMap<String, Object>();
		pager.setSearchMap(searchMap);
		pager = tbLogService.findPager(pager);
		return "systemLog";
	}

	// 删除
	public String delete() {
		final StringBuffer logInfoStringBuffer = new StringBuffer("删除日志: ");
		for (final Long id : ids) {
			final TbLog ss = tbLogService.load(id);
			tbLogService.delete(ss);
		}
		logInfo = logInfoStringBuffer.toString();
		return ajax(Status.success, "删除成功!");
	}

	/*
	 * //更改状态是否有效无效 public String updateStatus() { StringBuffer
	 * logInfoStringBuffer = new StringBuffer("更改状态"); String id =
	 * super.getRequest().getParameter("id"); String state =
	 * super.getRequest().getParameter("state"); TbLog ss =
	 * tbLogService.load(Long.valueOf(id)); ss.setState(state);
	 * tbLogService.update(ss); logInfo = logInfoStringBuffer.toString(); return
	 * ajax(Status.success, "更改状态成功!"); }
	 */

	// 添加
	public String add() {
		return INPUT;
	}

	// 编辑
	public String edit() {
		tbLog = tbLogService.load(id);
		return INPUT;
	}

	// 保存
	public String save() {
		tbLogService.save(tbLog);
		logInfo = "添加日志: " + tbLog.getId();
		return ajax(Status.success, "添加日志成功");
	}

	// 更新
	public String update() {
		final TbLog persistent = tbLogService.load(id);
		persistent.setLtype(tbLog.getLtype());
		persistent.setModule(tbLog.getModule());
		persistent.setUsername(tbLog.getUsername());
		persistent.setLcontent(tbLog.getLcontent());
		persistent.setCreateDate(tbLog.getCreateDate());
		tbLogService.update(persistent);
		logInfo = "编辑日志: " + tbLog.getId();
		return ajax(Status.success, "修改日志成功");
	}

	public TbLog getTbLog() {
		return tbLog;
	}

	public void setTbLog(TbLog tbLog) {
		this.tbLog = tbLog;
	}

}